<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/26 0026
 * Time: 16:20
 */
namespace s_time_task;

/**
 * 进程池测试
 *
 * Class PoolTest
 * @package s_time_task
 */
class PoolTest {

    public $workerNum = 2;

    public function index() {
        $pool = new \Swoole\Process\Pool($this->workerNum);

        $pool->on("WorkerStart", function ($pool, $workerId) {
            echo "Worker#{$workerId} is started" . PHP_EOL;
            //$process = $pool->getProcess();
            //$process->exec("/bin/sh", ["-c", 'ls -l']);
        });

        $pool->on("WorkerStop", function ($pool, $workerId) {
            echo "Worker#{$workerId} is stopped" . PHP_EOL;
        });

        $pool->start();
    }

}

$poolM =  new PoolTest();
$poolM->index();